package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.OmsOrderReturnApplyMapper;
import com.mall.model.domain.OmsOrderReturnApply;
import com.mall.model.dto.OmsOrderReturnApplyDto;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xyiaao
 * @description 针对表【oms_order_return_apply(订单退货申请)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class OmsOrderReturnApplyApiImpl extends ServiceImpl<OmsOrderReturnApplyMapper, OmsOrderReturnApply>
        implements OmsOrderReturnApplyApi {

    @Autowired
    private OmsOrderReturnApplyMapper omsOrderReturnApplyMapper;


    @Override
    public Page<OmsOrderReturnApply> pageByOmsOrderReturnApplyDto(OmsOrderReturnApplyDto omsOrderReturnApplyDto) {

        Page<OmsOrderReturnApply> page = new Page<>(omsOrderReturnApplyDto.getPageNum(), omsOrderReturnApplyDto.getPageSize());

        LambdaQueryWrapper<OmsOrderReturnApply> queryWrapper = new LambdaQueryWrapper<>();
        // 申请日期
        queryWrapper.apply(StringUtils.isNotEmpty(omsOrderReturnApplyDto.getCreateTime()), "DATE_FORMAT(create_time, '%Y-%m-%d') = {0}", omsOrderReturnApplyDto.getCreateTime())
                // 处理时间
                .apply(StringUtils.isNotEmpty(omsOrderReturnApplyDto.getHandleTime()), "DATE_FORMAT(handle_time, '%Y-%m-%d') = {0}", omsOrderReturnApplyDto.getHandleTime())
                // 处理人员
                .like(StringUtils.isNotEmpty(omsOrderReturnApplyDto.getHandleMan()), OmsOrderReturnApply::getHandleMan, omsOrderReturnApplyDto.getHandleMan())
                // 服务单号
                .like(omsOrderReturnApplyDto.getId() != null, OmsOrderReturnApply::getId, omsOrderReturnApplyDto.getId())
                // 退货人姓名
                .like(StringUtils.isNotEmpty(omsOrderReturnApplyDto.getReceiverKeyword()), OmsOrderReturnApply::getReturnName, omsOrderReturnApplyDto.getReceiverKeyword())
                // 退货人号码
                .or().like(StringUtils.isNotEmpty(omsOrderReturnApplyDto.getReceiverKeyword()), OmsOrderReturnApply::getReturnPhone, omsOrderReturnApplyDto.getReceiverKeyword())
                // 订单状态
                .eq(omsOrderReturnApplyDto.getStatus() != null, OmsOrderReturnApply::getStatus, omsOrderReturnApplyDto.getStatus())
                // 按创建时间倒序排序
                .orderByDesc(OmsOrderReturnApply::getCreateTime);

        return omsOrderReturnApplyMapper.selectPage(page, queryWrapper);
    }

}




